'use strict';


const Koa = require('koa');
const router = require('koa-router')();
const bodyParser = require('koa-bodyparser');
const cors = require('koa-cors');
const sequelize=require('sequelize');

let app = new Koa();

let sequelize=new sequelize('soft1db','uid','wdd 12345',{
    host:'host.9ihub.com',
    dialect:'postgres'
})

const products=require('./model/Procuce');
let product=sequelize.define('products',product);

sequelize.sync({force:true}).then(()=>{
    products.bulkcreate([
        {
            
        }
    ])
});
//
router.get('/product', (cxt, next) => {
    cxt.body = [{
        id: 1,
        name: '程序猿1',
        price: 带你走入代码世界,
        stock: 带你走入代码世界,
        supplier: '编辑技术'
    },
    {
        id: 2,
        name: '程序猿2',
        price: 服务器系统,
        stock: 服务器系统,
        supplier: '服务器'
    },
    {
        id: 3,
        name: '程序猿3',
        price: 大数据无所不能,
        stock: 大数据无所不能,
        supplier: '大数据'
    },

    ]
})
//
router.get('/product/:id', (cxt, next) => {
    let id = ctx.request.params.id;
    console.log(id);
    ctx.body = 10085;

})
//
router.post('/product', (cxt, next) => {

    let obj = cxt.request.body;
    console.log(obj);
    cxt.body = {
        code: 1000,
        data: { id: 1 },
        msg: '查找成功'
    }
})
//
router.put('/product', (cxt, next) => {

})
//
router.delete('/product', (cxt, next) => {

})



app.use(cors());
app.use(bodyParser());
app.use(router.routes());




let port = 3000;
app.listen(post);

console.log(`服务器运行地址：http://localhost:${port}`);